Conditions | 2 |
Paths | 32 |
Total Lines | 57 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | $(function(){ |
||
77 | $("body").delegate(":not(form)[data-role='ajax-request']", "click", function(event) |
||
78 | { |
||
79 | event.preventDefault(); |
||
80 | |||
81 | var url = $(this).attr('data-url'); |
||
82 | var type = $(this).attr('data-type'); |
||
83 | var box = $(this).attr('data-response'); |
||
84 | var data = $(this).attr('data-object'); |
||
85 | var frm = $(this).attr('data-form'); |
||
86 | |||
87 | var call = eval($(this).attr('data-callback')) || {}; |
||
88 | |||
89 | call.complete = call.complete || new Function(); |
||
90 | call.success = call.success || new Function(); |
||
91 | call.before = call.before || new Function(); |
||
92 | call.error = call.error || new Function(); |
||
93 | |||
94 | var form_data = $(frm).serializeArray(); |
||
95 | |||
96 | var parsed = eval(data); |
||
97 | |||
98 | for (var i in parsed) |
||
99 | { |
||
100 | form_data.push({ name: i, value: parsed[i] }); |
||
101 | } |
||
102 | |||
103 | $.ajax({ |
||
104 | url: url, |
||
105 | type: type, |
||
106 | data: form_data, |
||
107 | beforeSend: function() { |
||
108 | var loader = "<div class='ui active inline loader'></div>"; |
||
109 | $(box).html(loader); |
||
110 | call.before(); |
||
111 | }, |
||
112 | error: function(jqXHR, textStatus, errorThrown) |
||
113 | { |
||
114 | $(box).html("Error processing request!. " + errorThrown); |
||
115 | |||
116 | var e = {}; |
||
117 | e.jqXHR = jqXHR; |
||
118 | e.textStatus = textStatus; |
||
119 | e.errorThrown = errorThrown; |
||
120 | |||
121 | call.error(e); |
||
122 | }, |
||
123 | success: function(data) |
||
124 | { |
||
125 | $(box).html(data); |
||
126 | call.success(data); |
||
127 | }, |
||
128 | complete: function() |
||
129 | { |
||
130 | call.complete(); |
||
131 | } |
||
132 | }); |
||
133 | }); |
||
134 | }); |